from rest_framework.views import APIView
from rest_framework.response import Response
from api.serializers.account import MessageSerializer
from django_redis import get_redis_connection
import random
class LoginView(APIView):

    def post(self, request):
        print(request.data)
        return Response({'status': '200', 'data': ''})


class MessageView(APIView):

    def get(self, request):
        ser=MessageSerializer(data=request.query_params)
        if ser.is_valid():
            phone=ser.validated_data.get('phone')
            code=random.randint(1000,9999)
            conn=get_redis_connection()
            conn.set(phone,code,ex=30)

            return Response({'status': '200', 'data': ''})
        else:
            return Response({'status': '400', 'data': '','error':'手机格式错误'})
